package org.bongo.open.cumulo.procengine.runner;

import org.bongo.open.cumulo.core.message.MessageUnit;
import org.bongo.open.cumulo.procengine.broker.exceptions.ProcRunnerException;

public class SimpleProcRunner implements ProcRunner {

	public int runnerIndex;
	public ProcRunnerContainer container;
	
	public ProcRunnerContainer getContainer() {
		return container;
	}

	public SimpleProcRunner() {
	}
	
	public SimpleProcRunner(ProcRunnerContainer c) {
		setContainer(c);
		
	}
	
	public void setContainer(ProcRunnerContainer c) {
		container = c;
	}

	public void runOnContainer(MessageUnit<?> message) throws ProcRunnerException {
		if(container == null)
			throw new RuntimeException("ProcRunnerContainer is not set, call setContainer() first");
		
		container.run(message);
	}

	public void setRunnerIndex(int index) {
		runnerIndex = index;
		try {
			container.startup(null);
			container.setIdentifier(index);
		} catch (ProcRunnerException e) {
			e.printStackTrace();
		}
		
	}

}
